<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
    *{
        margin:0;
        padding: 0;
        box-sizing: border-box;
    }
    .main{
        width: 1000px;
        margin:20px auto;
    }
    .buttons{
        width: 100%;
        display: flex;
    }
    .buttons > input{
        flex: 1;
    }
    .box{
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        margin-top: 10px;
    }
    .box > img{
        width: 23%;
        display: block;
        margin-bottom: 10px;
    }
    .box > img:hover{
        box-shadow: 0 0 4px 2px gray;
    }
    </style>
</head>
<body>
    <div class="main">
        <div class="buttons">
            <input type="button" value="上一页" id="Last"> 
            <input type="button" value="下一页" id="Next">
        </div>
        <div id="box" class="box"></div>
    </div>
</body>
    
</body>
    
</body>
<script>

    // 1.获取事件
    var box = document.getElementById('box');
    var Next = document.getElementById('Next');
    var Last = document.getElementById('Last');

    // 2.获取数据
    var arrs = ['   ./images/00_03.png','./images/00_04.png','./images/00_05.png',
                    './images/00_06.png','./images/00_07.png','./images/00_24.png',
                    './images/00_16.png','./images/00_10.png','./images/00_11.png',
                    './images/00_12.png','./images/00_13.png','./images/00_14.png',
                    './images/00_16.png','./images/00_17.png','./images/00_18.png',
                    './images/00_19.png','./images/00_20.png','./images/00_26.png',
                    './images/00_22.png','./images/00_23.png',]
    // 3.遍历数组 在当前页展示
    function Myfunction(Start,End){
        var html = '';
        for(var i = Start;i <= End;i++){
            html += '<img src = "'+arrs[i]+'">'
        }
        box.innerHTML = html;
    }
    Myfunction(0,7);
    // 4. 下一页事件
    // 4.1定义第一页
    var pagination = 1;
    Next.onclick = function(){
        // 4.2 判断没有数据的话告诉用户
        if(pagination === Math.ceil(arrs.length / 8)){
            alert('再见啦!')
            return;
        }
        // 4.3 先切换到下一页再展示商品
        pagination++;
        var Start = (pagination - 1) * 8;
        var End = Start + 7;
        if(End === arrs.length - 1){
            End = arrs.length - 1;
        }
        Myfunction(Start,End)
    }
    // 5. 上一页切换
    Last.onclick = function(){
        // 5.1 判断当前为第一页的话 告诉用户无多余的数据 阻止代码的执行
        if(pagination === 1){
            alert('告辞')
            return;
        }
        pagination--;
        var Start = (pagination - 1) * 8;
        var End = Start + 7;
        Myfunction(Start,End)
    }
</script>
</html>